/*******************************************************************
*
* 		Replication files for "UN Peacekeeping and the Rule of Law"
* 		Robert A. Blair
* 		Brown University
* 		robert_blair@brown.edu
*
********************************************************************/


		clear
		set more off
		clear mata
		clear matrix
		graph set window fontface "Times"

		
		
* Setup
	
		cd "[YOUR DIRECTORY]"
			
		gl OUTPUT "output"

		use "data.dta", clear
		
		

		
* Globals


		gl ictrls_3l_varying_trunc_alt iwdipopt_3l iwdipcapc_3l iwdialldd_3l iwlccimr_3l ipolxintp_alt_3l iwlcbk100_3l 
				
		gl ictrls_invariant feeelf maxintensitylevel_coverall maxnumber_rebels_coverall
		

		
		
* Programs
	
		cap program drop make_figure_w_legend

			program define make_figure_w_legend

			syntax varlist, INDVAR(string) XLABMIN(real) XLABMAX(real) XLABDELTA(real) FILENAME(string)

				local depvar `varlist'
				local label: var label `indvar' 

				foreach time in ucdp ucdp_1yrs ucdp_2yrs ucdp_3yrs {
					xtreg `depvar' `indvar' $ictrls_3l_varying_trunc_alt if `time'==1, fe
						est sto `time'
						}
				
				coefplot (ucdp, label(Civil war) keep(`indvar') ciopts(lcolor(black) lpattern(solid)) mcolor(black) msymbol(square) ) ///
					(ucdp_1yrs, label(1+ year of peace) keep(`indvar') ciopts(lcolor(black) lpattern(dash)) mcolor(black) msymbol(triangle)) ///
					(ucdp_2yrs, label(2+ years of peace) keep(`indvar') ciopts(lcolor(black) lpattern(longdash)) mcolor(black) msymbol(circle)) ///
					(ucdp_3yrs, label(3+ years of peace) keep(`indvar') ciopts(lcolor(black) lpattern(vshortdash)) mcolor(black) msymbol(diamond)), ///
						graphr(color(white)) xline(0, lcolor(black) lwidth(thin)) ///
						legend(region(col(white)) cols(1) ring(0) bplacement(ne)) ///
						ytitle("", margin(medsmall)) ///
						xtitle("Coefficient on `label'", margin(medsmall)) xlab(`xlabmin'(`xlabdelta')`xlabmax') 
						gr_edit .yaxis1.draw_view.setstyle, style(no)
				graph export "$OUTPUT/`filename'.pdf", as(pdf) replace

		end

		
		cap program drop make_figure_wo_legend

			program define make_figure_wo_legend

			syntax varlist, INDVAR(string) XLABMIN(real) XLABMAX(real) XLABDELTA(real) FILENAME(string)

				local depvar `varlist'
				local label: var label `indvar' 

				foreach time in ucdp ucdp_1yrs ucdp_2yrs ucdp_3yrs {
					xtreg `depvar' `indvar' $ictrls_3l_varying_trunc_alt if `time'==1, fe
						est sto `time'
						}
				
				coefplot (ucdp, keep(`indvar') ciopts(lcolor(black) lpattern(solid)) mcolor(black) msymbol(square) ) ///
					(ucdp_1yrs, keep(`indvar') ciopts(lcolor(black) lpattern(dash)) mcolor(black) msymbol(triangle)) ///
					(ucdp_2yrs, keep(`indvar') ciopts(lcolor(black) lpattern(longdash)) mcolor(black) msymbol(circle)) ///
					(ucdp_3yrs, keep(`indvar') ciopts(lcolor(black) lpattern(vshortdash)) mcolor(black) msymbol(diamond)), ///
						graphr(color(white)) xline(0, lcolor(black) lwidth(thin)) ///
						legend(off) ///
						ytitle("", margin(medsmall)) ///
						xtitle("Coefficient on `label'", margin(medsmall)) xlab(`xlabmin'(`xlabdelta')`xlabmax') 
						gr_edit .yaxis1.draw_view.setstyle, style(no)
				graph export "$OUTPUT/`filename'.pdf", as(pdf) replace

		end
		
	

	
	
* Analysis
	

	
	* Figure 1

	
		make_figure_w_legend RoL, indvar(iactual_civilian_totalK_2l) xlabmin(-.2) xlabdelta(.1) xlabmax(.45) filename(figure1b)

		make_figure_wo_legend RoL, indvar(itotal_compoundK_2l) xlabmin(-.2) xlabdelta(.1) xlabmax(.45) filename(figure1a)

		make_figure_wo_legend RoL, indvar(iapproved_RoL_totalK_2l) xlabmin(-.2) xlabdelta(.1) xlabmax(.45) filename(figure1c)

		make_figure_wo_legend RoL, indvar(irol_all_max_dum_2l) xlabmin(-.2) xlabdelta(.1) xlabmax(.45) filename(figure1d)

	
				
				
	* Figure 2

		make_figure_w_legend law, indvar(iactual_civilian_totalK_2l) xlabmin(-1) xlabdelta(.5) xlabmax(3.5) filename(figure2b)

		make_figure_wo_legend law, indvar(itotal_compoundK_2l) xlabmin(-1) xlabdelta(.5) xlabmax(3.5) filename(figure2a)

		make_figure_wo_legend law, indvar(iapproved_RoL_totalK_2l) xlabmin(-1) xlabdelta(.5) xlabmax(3.5) filename(figure2c)

		make_figure_wo_legend law, indvar(irol_all_max_dum_2l) xlabmin(-1) xlabdelta(.5) xlabmax(3.5) filename(figure2d)

	
								

	* Figure 3

		make_figure_w_legend RoL, indvar(icourts_all_max_dum_2l) xlabmin(-.2) xlabdelta(.1) xlabmax(.45) filename(figure3b)

		make_figure_wo_legend RoL, indvar(ipol_all_max_dum_2l) xlabmin(-.2) xlabdelta(.1) xlabmax(.45) filename(figure3a)

		make_figure_wo_legend RoL, indvar(iprison_all_max_dum_2l) xlabmin(-.2) xlabdelta(.1) xlabmax(.45) filename(figure3c)

		make_figure_wo_legend RoL, indvar(ilegal_all_max_dum_2l) xlabmin(-.2) xlabdelta(.1) xlabmax(.45) filename(figure3d)
	
				  
				
	* Figure 4

		make_figure_w_legend law, indvar(icourts_all_max_dum_2l) xlabmin(-1) xlabdelta(.5) xlabmax(3.5) filename(figure4b)

		make_figure_wo_legend law, indvar(ipol_all_max_dum_2l) xlabmin(-1) xlabdelta(.5) xlabmax(3.5) filename(figure4a)

		make_figure_wo_legend law, indvar(iprison_all_max_dum_2l) xlabmin(-1) xlabdelta(.5) xlabmax(3.5) filename(figure4c)

		make_figure_wo_legend law, indvar(ilegal_all_max_dum_2l) xlabmin(-1) xlabdelta(.5) xlabmax(3.5) filename(figure4d)

				
	
	
	* Table 1
				

		local title "table1"
		global indvars irol_engagement_max_dum_2l irol_implement_max_dum_2l

		cap erase "$OUTPUT/`title'.xls"
		cap erase "$OUTPUT/`title'.txt"	

		foreach depvar in RoL law {
			foreach time in ucdp ucdp_1yrs ucdp_2yrs ucdp_3yrs {
				xtreg `depvar' $indvars $ictrls_3l_varying_trunc_alt if `time'==1, fe
					outreg2 using "$OUTPUT/`title'.xls", excel aster(se) dec(2) br keep($indvars) lab nocons append ///
						addtext(Time, `time')			
					}
				}
				
				
	
	* Figure 5

		make_figure_w_legend RoL, indvar(irol_assist_max_dum_2l) xlabmin(-.2) xlabdelta(.1) xlabmax(.45) filename(figure5b)

		make_figure_wo_legend RoL, indvar(irol_support_max_dum_2l) xlabmin(-.2) xlabdelta(.1) xlabmax(.45) filename(figure5a)

		make_figure_wo_legend RoL, indvar(irol_advocate_max_dum_2l) xlabmin(-.2) xlabdelta(.1) xlabmax(.45) filename(figure5c)

		make_figure_wo_legend RoL, indvar(irol_monitor_max_dum_2l) xlabmin(-.2) xlabdelta(.1) xlabmax(.45) filename(figure5d)


		
				
	* Figure 6

		make_figure_w_legend law, indvar(irol_assist_max_dum_2l) xlabmin(-1) xlabdelta(.5) xlabmax(3.5) filename(figure6b)

		make_figure_wo_legend law, indvar(irol_support_max_dum_2l) xlabmin(-1) xlabdelta(.5) xlabmax(3.5) filename(figure6a)

		make_figure_wo_legend law, indvar(irol_advocate_max_dum_2l) xlabmin(-1) xlabdelta(.5) xlabmax(3.5) filename(figure6c)

		make_figure_wo_legend law, indvar(irol_monitor_max_dum_2l) xlabmin(-1) xlabdelta(.5) xlabmax(3.5) filename(figure6d)


		
		
		drop _est*
		
		


				

		
		
				
		
